package com.jerome.election.server;

/**
 * 成员状态
 * 参考 Raft
 * @author jerome
 * @date 2023/7/28
 */
public enum MemberStateEnum {
    //LEADER 状态,
    LEADER("LEADER"),
    //FOLLOWER 状态
    FOLLOWER("FOLLOWER"),
    //CANDIDATE 状态
    CANDIDATE("CANDIDATE"),
    // ACCEPTER状态为固定态,状态将固定不变
    ACCEPTER("ACCEPTER"),
    ;

    public static MemberStateEnum getByCode(String code){
        for (MemberStateEnum value : MemberStateEnum.values()) {
            if (code.equals(value.code)){
                return value;
            }
        }
        return FOLLOWER;
    }

    private String code;

    MemberStateEnum(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
    
}
